package com.chonglie;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.GridView;
import android.widget.SimpleAdapter;
import android.widget.TextView;

public class GridViewActivity extends Activity {

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.grid_view);
		fillGridView();
	}

	private void fillGridView() {
		GridView view = (GridView) findViewById(R.id.gridview_gridview);

		List<Map<String, Object>> records = new ArrayList<Map<String, Object>>();

		Map<String, Object> map;
		for (int i = 0; i < 9; i++) {
			map = new HashMap<String, Object>();
			map.put("image", R.drawable.ic_launcher);
			map.put("content", "content " + i);
			records.add(map);
		}

		SimpleAdapter sa = new SimpleAdapter(this, records,
				R.layout.grid_view_item, new String[] { "image", "content" },
				new int[] { R.id.gridview_item_image,
						R.id.gridview_item_content });
		view.setAdapter(sa);
	}

	public void setTitle(View view) {
		TextView textView = (TextView) view
				.findViewById(R.id.gridview_item_content);
		this.setTitle(textView.getText());
	}
}
